//
//  CellOfHot_areaHead.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/8.
//  Copyright © 2016年 KX. All rights reserved.
#import "TravelShopViewController.h"
#import "DetailsPageOfCellOfCollectionViewOfService.h"
#import "ModelOfHot_areaPlace.h"
#import "UIImageView+WebCache.h"
#import "CellOfHot_areaHead.h"
#import "Masonry.h"
#import "FreeTravelMacro.h"
@interface CellOfHot_areaHead ()

@property (nonatomic, strong) UILabel *secondlabelOfName;
@property (nonatomic, strong) UIImageView *secondimageViewOfPhoto;
@property (nonatomic, strong) UILabel *firstlabelOfName;
@property (nonatomic, strong) UIImageView *firstimageViewOfPhoto;
@property (nonatomic, strong) UILabel *thirdlabelOfName;
@property (nonatomic, strong) UIImageView *thirdimageViewOfPhoto;
@property (nonatomic, strong) UILabel *forthlabelOfName;
@property (nonatomic, strong) UIImageView *forthimageViewOfPhoto;

@end
@implementation CellOfHot_areaHead
- (instancetype)initWithFrame:(CGRect)frame{
    self= [super initWithFrame:frame];
    if (self) {
        self.label = [[UILabel alloc]init];
        self.firstlabelOfName = [[UILabel alloc]init];
        self.firstimageViewOfPhoto = [[UIImageView alloc]init];
        self.secondlabelOfName = [[UILabel alloc]init];
        self.secondimageViewOfPhoto = [[UIImageView alloc]init];
        self.thirdlabelOfName = [[UILabel alloc]init];
        self.thirdimageViewOfPhoto = [[UIImageView alloc]init];
        self.forthlabelOfName = [[UILabel alloc]init];
        self.forthimageViewOfPhoto = [[UIImageView alloc]init];
        [self addSubview:self.firstimageViewOfPhoto];
        [self addSubview:self.firstlabelOfName];
        [self addSubview:self.secondimageViewOfPhoto];
        [self addSubview:self.secondlabelOfName];
        [self addSubview:self.thirdimageViewOfPhoto];
        [self addSubview:self.thirdlabelOfName];
        [self addSubview:self.forthimageViewOfPhoto];
        [self addSubview:self.forthlabelOfName];
        [self addSubview:self.label];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.firstimageViewOfPhoto.mas_top);
    }];
    self.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.f];
    [self.firstimageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).mas_offset(10);
        make.bottom.equalTo(self.mas_bottom).mas_offset(-10);
        make.width.mas_offset((SCREEN_WIDTH-50)/4);
        make.height.equalTo(self.firstimageViewOfPhoto.mas_width);
    }];
    [self.firstlabelOfName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.firstimageViewOfPhoto.mas_centerX);
        make.centerY.equalTo(self.firstimageViewOfPhoto.mas_centerY);
        
    }];
    
    [self.secondimageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).mas_offset(-10);
        make.width.mas_offset((SCREEN_WIDTH-50)/4);
        make.height.equalTo(self.firstimageViewOfPhoto.mas_height);
        make.left.equalTo(self.firstimageViewOfPhoto.mas_right).mas_offset(10);
    }];
    [self.secondlabelOfName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.secondimageViewOfPhoto.mas_centerX);
        make.centerY.equalTo(self.secondimageViewOfPhoto.mas_centerY);
    }];
    [self.thirdimageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).mas_offset(-10);
        make.width.mas_offset((SCREEN_WIDTH-50)/4);
        make.height.equalTo(self.firstimageViewOfPhoto.mas_height);
        make.left.equalTo(self.secondimageViewOfPhoto.mas_right).mas_offset(10);
    }];
    [self.thirdlabelOfName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.thirdimageViewOfPhoto.mas_centerX);
        make.centerY.equalTo(self.thirdimageViewOfPhoto.mas_centerY);
    }];
    [self.forthimageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).mas_offset(-10);
        make.width.mas_offset((SCREEN_WIDTH-50)/4);
        make.height.equalTo(self.firstimageViewOfPhoto.mas_height);
        make.left.equalTo(self.thirdimageViewOfPhoto.mas_right).mas_offset(10);
    }];
    [self.forthlabelOfName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.forthimageViewOfPhoto.mas_centerX);
        make.centerY.equalTo(self.forthimageViewOfPhoto.mas_centerY);
    }];
    self.firstlabelOfName.textColor = [UIColor whiteColor];
    self.firstlabelOfName.font = self.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.f];
    self.secondlabelOfName.textColor = [UIColor whiteColor];
    self.secondlabelOfName.font = self.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.f];
    self.thirdlabelOfName.textColor = [UIColor whiteColor];
    self.thirdlabelOfName.font = self.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.f];
    self.forthlabelOfName.textColor = [UIColor whiteColor];
    self.forthlabelOfName.font = self.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.f];
    
    _firstimageViewOfPhoto.userInteractionEnabled = YES;
    
    _secondimageViewOfPhoto.userInteractionEnabled = YES;
    
    
    _thirdimageViewOfPhoto.userInteractionEnabled = YES;
    
    _forthimageViewOfPhoto.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap1  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goTap1:)];
    UITapGestureRecognizer *tap2  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goTap2:)];
    UITapGestureRecognizer *tap3  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goTap3:)];
    UITapGestureRecognizer *tap4  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goTap4:)];
    [_firstimageViewOfPhoto addGestureRecognizer:tap1];
    [_secondimageViewOfPhoto addGestureRecognizer:tap2];
    [_thirdimageViewOfPhoto addGestureRecognizer:tap3];
    [_forthimageViewOfPhoto addGestureRecognizer:tap4];
    
}
- (void)goTap1:(UITapGestureRecognizer *)tap1{

    DetailsPageOfCellOfCollectionViewOfService *vc = [[DetailsPageOfCellOfCollectionViewOfService alloc]init];
    TravelShopViewController *travel = (TravelShopViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    ModelOfHot_areaPlace *model1 = self.model.place[0];
    vc.string = model1.name;
    [travel.navigationController pushViewController:vc animated:YES];
    
    
}
- (void)goTap2:(UITapGestureRecognizer *)tap2{
    DetailsPageOfCellOfCollectionViewOfService *vc = [[DetailsPageOfCellOfCollectionViewOfService alloc]init];
    TravelShopViewController *travel = (TravelShopViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    ModelOfHot_areaPlace *model2 = self.model.place[1];
    vc.string = model2.name;
    [travel.navigationController pushViewController:vc animated:YES];

}
- (void)goTap3:(UITapGestureRecognizer *)tap3{
    DetailsPageOfCellOfCollectionViewOfService *vc = [[DetailsPageOfCellOfCollectionViewOfService alloc]init];
    TravelShopViewController *travel = (TravelShopViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    ModelOfHot_areaPlace *model3 = self.model.place[2];
    vc.string = model3.name;
    [travel.navigationController pushViewController:vc animated:YES];

}
- (void)goTap4:(UITapGestureRecognizer *)tap4{
    DetailsPageOfCellOfCollectionViewOfService *vc = [[DetailsPageOfCellOfCollectionViewOfService alloc]init];
    TravelShopViewController *travel = (TravelShopViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    ModelOfHot_areaPlace *model4 = self.model.place[3];
    vc.string = model4.name;
    [travel.navigationController pushViewController:vc animated:YES];

}
- (void)setModel:(ModelOfHot_area *)model{
    _model = model;
    if ([self.model.type isEqualToString:@"om"]) {
        self.label.text = @"欧洲美国";
    }else if ([self.model.type isEqualToString:@"gat"]){
        self.label.text = @"港澳台";
    }else if ([self.model.type isEqualToString:@"dny"]){
        self.label.text = @"东南亚";
    }else if([self.model.type isEqualToString:@"rh"]){
        self.label.text = @"日韩";
    }else{
        self.label.text = @"";
    }

    ModelOfHot_areaPlace *model1 = self.model.place[0];
    ModelOfHot_areaPlace *model2 = self.model.place[1];
    ModelOfHot_areaPlace *model3 = self.model.place[2];
    ModelOfHot_areaPlace *model4 = self.model.place[3];
    self.firstlabelOfName.text = model1.name;
    self.secondlabelOfName.text = model2.name;
    self.thirdlabelOfName.text = model3.name;
    self.forthlabelOfName.text = model4.name;
    [self.firstimageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model1.photo]];
    [self.secondimageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model2.photo]];
    [self.thirdimageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model3.photo]];
    [self.forthimageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model4.photo]];
    
}
@end
